﻿using System;
using Data;

namespace Presenter
{
    public class ClientPresenter
    {
        private IClient _view;
        private ClientInformation _data;                                            // விவர தளத்தை தொடர்பு கொள்ள

        public ClientPresenter(IClient view)
            : this(view, new ClientInformation())
        { }

        public ClientPresenter(IClient view, ClientInformation data)
        {
            _view = view;
            _data = data;
            _view.Message = "Welcome to Appointment Manager" + "                     " + DateTime.Now.ToShortDateString();
        }

        public void UpdateData(string searchTerm)
        {
            try
            {
                if (searchTerm != string.Empty)
                {
                    Client client = _data.ReadData(searchTerm);                     // விவரங்களை பெறுவதற்கு
                    _view.FullName = client.Name;
                    _view.Email = client.Email;
                    _view.Address = client.Street;
                    _view.Zip = client.Zip;
                    _view.State = client.State;
                    _view.Message = "Search completed" + "                     " + DateTime.Now.ToShortDateString();
                }
            }
            catch (Exception e)
            {
                _view.Message = e.Message;
            }
        }

        public void ClearData()
        {
            _view.FullName = string.Empty;
            _view.Email = string.Empty;
            _view.Address = string.Empty;
            _view.Zip = string.Empty;
            _view.State = string.Empty;
            _view.Message = "Data Cleared" + "                                      " + DateTime.Now.ToShortDateString();
        }
    }
}
